package gof_003_行为型_Behavioral.gof_011_解释器_Interpreter;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.stream.Collectors;

public class Main {
    public static List<Integer> str2IntList(String str) {
        return str2IntList(str,",");
    }
    public static List<Integer> str2IntList(String str,String split) {
        if (str == null || "".equals(str.trim())) {
            return new ArrayList<>();
        }
        List<Integer> intList = Arrays.stream(str.split(split)).map(i -> {
            try {
                return Integer.parseInt(i);
            } catch (Exception e) {
                System.out.println(i + " 转换为 Integer 异常,置为 0");
                return 0;
            }
        }).collect(Collectors.toList());
        return intList;
    }

    public static void main(String[] args) {
        List<Integer> integerList = str2IntList("1,23,23000000000");
        integerList.forEach(System.out::println);
    }
}
